/**
 * Baijiahulian.com Inc. Copyright (c) 2014-2016 All Rights Reserved.
 */
package com.baijia.authentication.principal.populator;

import com.baijia.authentication.Authentication;
import com.baijia.authentication.principal.Credentials;
import com.baijia.authentication.principal.credentials.OrgTeacherCredentials;
import com.baijia.common.enums.UserRoleType;

import org.springframework.stereotype.Component;

/**
 * @title UserMetaDataPopulator
 * @desc TODO
 * @author macrohuang
 * @date Jan 20, 2016
 * @version 1.0
 */
@Component
public class OrgTeacherMetaDataPopulator extends UserMetaDataPopulator {

    @Override
    public boolean supports(Credentials credentials) {
        return credentials instanceof OrgTeacherCredentials;
    }

    @Override
    public Authentication populateAttributes(Authentication authentication, Credentials credentials) {
        Authentication orgTeacherAuthentication = super.populateAttributes(authentication, credentials);
        orgTeacherAuthentication.getAttributes().put(Credentials.USER_ROLE, UserRoleType.ORG_TEACHER.getId());

        return orgTeacherAuthentication;
    }
}